#pragma once
#include "common.h"
#include "BTCOMConn.h"
#include "GPSMeterPanel.h"
#include "../nmealib/include/nmea/parser.h"
#include "../nmealib/include/nmea/gmath.h"

class CGPSViewWnd : public CMzWndEx
{
    MZ_DECLARE_DYNAMIC(CGPSViewWnd);
private:
    deque<string>       m_qSentenceQueue;
    nmeaINFO            m_NMEAInfo;
    CRITICAL_SECTION    m_SentenceQueueCS;
    CRITICAL_SECTION    m_NMEAInfoCS;

public:
    CBTCOMConn          *m_pConn;

public:
    UiCaption           m_uCaption;
    UiToolbar_Text      m_uToolbar;

public:
    UiStatic            m_uGPSTime;
    UiStatic            m_uGPSLongitude;
    UiStatic            m_uGPSLatitude;
    UiStatic            m_uGPSAltitude;
    UiStatic            m_uGPSDirection;
    UiStatic            m_uGPSSpeed;
    UiStatic            m_uGPSSatellitesCount;
    CGPSMeterPanel      m_uGPSMeterPanel;


public:
    HANDLE              m_hSerialPort;
    HANDLE              m_hReadThread;
    DWORD               m_dReadThreadId;

friend DWORD WINAPI ReadThreadFunc(LPVOID lpvoid);
friend DWORD WINAPI ParseThreadFunc(LPVOID lpvoid);

public:
    string PopSentence();
    void PushSentence(const string sentence);

    nmeaINFO *GetNMEAInfo();
    void SetNMEAInfo(const nmeaINFO info);

public:
    virtual BOOL OnInitDialog();
    virtual void OnMzCommand(WPARAM wParam, LPARAM lParam);
    virtual void OnTimer(UINT_PTR nIDEvent);
    LRESULT MzDefWndProc(UINT message, WPARAM wParam, LPARAM lParam);

public:
    CGPSViewWnd(CBTCOMConn &conn);
    ~CGPSViewWnd(void);
};
